package com.sky.loveshop.tcpClient;

import java.io.OutputStream;
import java.net.Socket;

/**
 * @author xcy
 * @version V1.0
 * @description
 * @date 2024/9/4 21:38
 */
public class TcpClientOpenDoor {

    /**
     * main方法测试发送tcp请求到设备进行开门
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        //String ip = "192.168.3.253";   //服务器端ip地址
        String ip = "server.natappfree.cc";   //服务器端ip地址
        //int port = 1030;        //端口号
        int port = 35297;        //端口号
        Socket sck = new Socket(ip, port);
        //2.传输内容
        String content = "{\"addr\":01,\"cmd\":\"set\",\"y\":[1,0],\"count\":[0,0],\"delay\":[5,0]}";
        byte[] bstream = content.getBytes("GBK");  //转化为字节流
        OutputStream os = sck.getOutputStream();   //输出流
        os.write(bstream);
        //3.关闭连接
        sck.close();
    }
}
